
//  customDismiss.m
//  testTransition3
//
//  Created by zsj1992 on 17/1/4.
//  Copyright © 2017年 bjhj. All rights reserved.
//

#import "customDismiss.h"
#import "ViewController.h"
#import "SecondViewController.h"

#define SCREEN_W [UIScreen mainScreen].bounds.size.width
#define SCREEN_H [UIScreen mainScreen].bounds.size.height

@interface customDismiss()
@property (nonatomic,strong)id transitionContext;

@end

@implementation customDismiss


-(NSTimeInterval)transitionDuration:(id<UIViewControllerContextTransitioning>)transitionContext{

    return 0.8;
}




-(void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext{
    

   
    

    SecondViewController * fromVc = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];

    ViewController * toVc = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];

    
    
    
    CGRect initFrame = [transitionContext initialFrameForViewController:fromVc];
    
    CGRect targetFrame = CGRectOffset(initFrame, 0, SCREEN_H);
    
    
    
    UIView * containerView = [transitionContext containerView];


    [containerView addSubview:toVc.view];
    [containerView sendSubviewToBack:toVc.view];
    
    
    NSTimeInterval duration = [self transitionDuration:transitionContext];

    [UIView animateWithDuration:duration animations:^{
     
        fromVc.view.frame = targetFrame;
        
    }completion:^(BOOL finished) {
        
        NSLog(@"complete1");
        
#pragma mark-zsj

        
        //  [transitionContext completeTransition:YES];
        
        [transitionContext completeTransition:![transitionContext transitionWasCancelled]];

        
    }];

    
    
    
}







@end
